import { ref } from 'vue';
import { IFootprintIndicator, IInventoryIndicator } from '@/apis/workbench/model/workbenchModel';
import dayjs from 'dayjs';
import { getFootprintIndicator, getInventoryIndicator } from '@/apis/workbench/index';
export const useNormBox = () => {
  const loading = ref(false);
  const footprintIndicator = ref<IFootprintIndicator>();
  const inventoryIndicator = ref<IInventoryIndicator>();

  const loadData = async () => {
    loading.value = true;
    try {
      footprintIndicator.value = (await getFootprintIndicator()) || {};
      inventoryIndicator.value = (await getInventoryIndicator()) || {};
    } finally {
      loading.value = false;
    }
  };
  const currentYear = dayjs().format('YYYY');
  const currentMonth = () => {
    const now = Number(dayjs().format('M'));
    if (now === 1) {
      return now;
    } else {
      return now - 1;
    }
  };
  loadData();
  return {
    loading,
    footprintIndicator,
    inventoryIndicator,
    currentYear,
    currentMonth
  };
};
